﻿/*

filipesilvestrim - An open-source ActionScript 3.0 repository of codes for Game Developers 

http://code.google.com/p/filipesilvestrim/

Copyright (c) 2009 Filipe Ghesla Silvestrim, All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

package com.filipesilvestrim.game.view
{	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.geom.Rectangle;

	public class View
	{
		// ___________________________________________________________________ CONSTANTS
		
		// ___________________________________________________________________ CLASS PROPERTIES
		private var _clipContent	: Boolean = false; 
		
		// ___________________________________________________________________ INSTANCE PROPERTIES
		private var _scope	 		: DisplayObjectContainer;
		private var _bounds	 		: Rectangle; //FIXME change by primitives
		
		// ___________________________________________________________________ GETTERS AND SETTERS
		public function get scope () 		: DisplayObjectContainer 	{ return _scope; }
		public function get bounds () 		: Rectangle					{ return _bounds; }
		public function get clipContent () 	: Boolean 					{ return _clipContent; }
		
		public function set bounds ( value : Rectangle ) : void
		{
			_bounds = value;
		}
		
		//FIXME com bug que tá reposicionando
		public function set clipContent ( value : Boolean ) : void
		{
			_clipContent = value;
			
			if (_clipContent)
				_scope.scrollRect = _bounds;
			else
				_scope.scrollRect = null;
		}
		
		// ___________________________________________________________________ CONSTRUCTOR
		
		public function View ( scope : DisplayObjectContainer, bounds : Rectangle = null ) 
		{
			_scope 	= scope;
			_bounds = new Rectangle();
		}
		
		// ___________________________________________________________________ PUBLIC METHODS
		public function debug ( where : Sprite = null) : void
		{
			var local 		: Sprite 	= where || (_scope as Sprite);
			var	thickness	: Number	= 2;
			var	tM			: Number	= thickness/2;
			
			local.graphics.clear();
			local.graphics.lineStyle(thickness);
			local.graphics.moveTo(_bounds.x + tM, _bounds.y + tM);
			local.graphics.lineTo(_bounds.x + _bounds.width - tM, _bounds.y + tM);
			local.graphics.lineTo(_bounds.x + _bounds.width - tM, _bounds.y + _bounds.height - tM);
			local.graphics.lineTo(_bounds.x + tM, _bounds.y + _bounds.height - tM);
			local.graphics.lineTo(_bounds.x + tM, _bounds.y + tM);
		}
		
		public function clear ( where : Sprite = null) : void
		{
			var local 		: Sprite 	= where || (_scope as Sprite);
			local.graphics.clear();
		}
		
		// ___________________________________________________________________ PRIVATE METHODS
		
		// ___________________________________________________________________ EVENTS
	}
}

